﻿Imports Lourdes.BackEnd.BC
Imports Lourdes.BackEnd.Modelo
Imports Lourdes.BackEnd.View
Public Class frmProductosAlternativosBuscar
  Public Event ProductoSeleccionado(ByVal pProducto As vProducto)
  Private _ListPrecioId As Integer
  Private _ProductosEnFactura As vLstProductos
  Private ProductoSel As vProducto = Nothing
  'Private AgregarAFactura As Boolean = False
  Private _ParentForm As frmProductosBuscar
  Public Property ListaPrecioId() As Integer
    Get
      Return _ListPrecioId
    End Get
    Set(ByVal value As Integer)
      _ListPrecioId = value
    End Set
  End Property

  Public Sub GetProductosAlternativos(ByVal pListPreciosId As Integer, ByVal pMercId As Integer, pMercDesc As String, pMercNum As String, Optional pParent As frmProductosBuscar = Nothing)
    Dim bcMerc As BC_Mercaderia
    Dim lstvProd As List(Of vProducto)
    _ListPrecioId = pListPreciosId
    Try
      _ParentForm = pParent
      bcMerc = New BC_Mercaderia
      lstvProd = bcMerc.GetMercViewAlternativas(pListPreciosId, pMercId)
      SetearControles(pMercDesc, pMercNum)
      CargarGrid(lstvProd)
      If pParent IsNot Nothing Then
        ShowDialog(pParent)
      Else
        ShowDialog()
      End If

    Catch ex As Exception
      Utils.ManejoErrores(ex)
    End Try
  End Sub
  Private Sub SetearControles(pMercDesc As String, pMercNum As String)
    txtCodigo.Text = pMercNum
    txtDescripcion.Text = pMercDesc
    txtCodigo.ReadOnly = True
    txtDescripcion.ReadOnly = True
  End Sub

  Private Sub CargarGrid(ByVal pLstvProducto As List(Of vProducto))
    Try
      With grdDatos
        .DataSource = pLstvProducto
        .DataBind()
        .Focus()
        If pLstvProducto.Count > 0 Then
          .Rows.FirstOrDefault.Selected = True
        End If
      End With
    Catch ex As Exception
      Utils.ManejoErrores(ex)
    End Try
  End Sub

  Private Sub grdDatos_DoubleClickRow(sender As System.Object, e As Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs) Handles grdDatos.DoubleClickRow
    Dim oProductoSel As vProducto
    oProductoSel = CType(e.Row.ListObject, vProducto)
    With _ParentForm
      .txtCodigo.Text = oProductoSel.MercaderiaNumero
      '.txtDescripcion.Text = oProductoSel.Nombre
      .CargarGrid()
    End With
    Me.Close()
  End Sub
End Class